
/* 
    账号相关api使用的 actions
*/
import { ADDUSER, GETUSERACCOUNT } from '../constant'
import { Dispatch } from 'redux'
import { setup, getAccount, addAccount, updateAccount } from "@/api/login"
import code from "@/api/constant"
import { message } from 'antd'


export const asyncAction = (data: userInfo): any => {
    return async (dispatch: Dispatch) => {
        const res = await setup(data)
        if (res.code == code.SUCCESS_CODE) {
            dispatch({ type: ADDUSER, data: res.data })
            return "success"
        }
        message.error(res.msg||"登录失败")
        return "error"

    }

}


export const getAccountAct = (data?: PageData): any => {

    return async (dispatch: Dispatch) => {
        const res = await getAccount(data)
        if (res.code == 1) {
            dispatch({ type: GETUSERACCOUNT, data: res.data })
            return res
        }
        return "error"
    }
}


export const addAccountAct = (data: addAccountType): any => {

    return async (dispatch: Dispatch) => {
        const res = await addAccount(data)
        if (res.code == 1) {
            return "success"
        }
        return "error"
    }

}


export const updateAccountAct = (data: accountDataType): any => {
    return async (dispatch: Dispatch) => {
        const res = await updateAccount(data)
        if (res.code == 1) {
            return "success"
        }
        return "error"
    }
}


